package com.hans.scala

/**
 * User: ZhangJuntao
 * Date: 14-3-14
 * Time: 下午4:57
 */
object FunctionTest {
  def testIncrease() {
    val increase = (x: Int) => {
      println("increase")
      x + 1
    }
    println(increase(2))
  }

  def main(args: Array[String]) {
    //    testIncrease()

    val someNumbers = List(-3, 34, -23, 3, 2, 10, 5)
    //    println(someNumbers)
    //    println(someNumbers.foreach((x: Int) => println(x)))
        println(someNumbers.filter((x: Int) => x > 5))
    //    println(someNumbers.filter(x => x > 5))
    //    println(someNumbers.filter(_ > 5))

    //    val f = (_: Int) + (_: Int)
    //    println(f(2, 3))
    //    someNumbers.foreach(println)

    //    testSum()

    //    var more=10
    //    val addMore = (x: Int) => x + more
    //    println(addMore(1))
    //    more=1
    //    println(addMore(1))

    val arr = Array("What's", "up", "doc?")
    //    def echo(args: String*) =
    //      for (arg <- args)
    //        println(arg)
    //
    //    echo(arr:_*)

    //    println(arr.exists(_ equals "up"))
    //    println(arr.exists(_ equals "ups"))

    testAssert()
  }

  def testAssert() {
    def myAssert(predicate: () => Boolean) =
      if (!predicate()) throw new AssertionError()

    def byNameAssert(predicate: => Boolean) =
      if (!predicate) throw new AssertionError()

    def boolAssert(predicate: Boolean) =
      if (!predicate) throw new AssertionError()

    //    myAssert(() => 5 < 3)
    //    byNameAssert(5 < 3)
    //    boolAssert(5 < 3)

//    byNameAssert(x / 0 == 0)
//    boolAssert(x / 0 == 0)

  }
}
